/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package complet.app.fe;

import com.google.gson.Gson;
import complet.helper.CompletData;
import complet.helper.IOHelper;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 *
 * @author paul
 */
public class CompletTestClient {

public static void main(String[] args) {
        try {
            //
            // Input
            //
            String[] words = {"weil", "ich", "nicht", "so"};
            String offset = "ka";
            CompletData data = new CompletData(words, offset, false);
            Gson json = new Gson();
            String s = json.toJson(data);

//            CompletData data2 = json.fromJson(s, CompletData.class);
//            System.out.println(data2.toSentence());
            //
            // Create a connection to the server socket on the server application
            //
            InetAddress host = InetAddress.getLocalHost();
            Socket socket = new Socket(host.getHostName(), 1337);

            //
            // Send a data
            //
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
            oos.writeObject(s);

            //
            // Read and display the response message sent by server application
            //
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            String result = (String) ois.readObject();
            
            System.out.println(result);

            ois.close();
            oos.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

}
